New uniqueness feature#1064
New uniqueness feature#1064bedeho merged 17 commits intoJoystream:content_directory_second_tryfrom iorveth:new_uniqueness_feature
Conversation
…oduce SimplifiedOutputPropertyValue to store property values unique on Class level
bedeho
left a comment
There was a problem hiding this comment.
-
Seems like removal from index was missed a few places, that needs to be added, and tests added that would trigger on failure. Perhaps update tests to fail frist?
-
Note that the
network-integration-testis not for any sort of unit testing, even in ther untime, its explicitly for the network wide integration tests which Gleb & Mokhtar currently are working on, it does not apply to this PR, so I removed the label.
| // | ||
|
|
||
| // Update property values, that should be unique on Class level | ||
| Self::add_unique_property_values(class_id, new_unique_property_values); |
There was a problem hiding this comment.
I believe that there is cleanup processing missing that removes possible old values from the uniqueness index. The tests should be updated to catch this case, and all instances of such missing logic across the extrinsic should be considered.
There was a problem hiding this comment.
Only default non required unique value hashes can be removed on update_entity_property_values operation. Implemented here 883863b#diff-0a165b042aa89a04d896ad36b8a33af5R1027
Additional test coverage for the previously discussed failure case fb19f62
| let empty_property_value_vector = Self::clear_property_vector(property_value_vector); | ||
|
|
||
| // Ensure provided `Property` with `unique` flag set is `unique` on `Class` level | ||
| Self::ensure_property_unique_option_satisfied(class_id, in_class_schema_property_id, &empty_property_value_vector.simplify())?; |
There was a problem hiding this comment.
This is basically a check that there is no empty vector for this, possible, unique property. Lets update the comment to say exactly that.
| // == MUTATION SAFE == | ||
| // | ||
|
|
||
| // Decrease reference counters of involved entities (if some) |
There was a problem hiding this comment.
Seems to be missing the same cleanup of old value from uniquness index.
There was a problem hiding this comment.
Only default non required unique value hashes can be removed, otherwise we only update its respective hash
| .get_vec_value() | ||
| .get_involved_entities() | ||
| .and_then(|involved_entities| involved_entities.get(index_in_property_vector as usize).copied()); | ||
| // Insert updated propery value into entity_property_values mapping at in_class_schema_property_id. |
There was a problem hiding this comment.
Only default non required unique value hashes can be removed, otherwise we only update its respective hash.
| // == MUTATION SAFE == | ||
| // | ||
|
|
||
| // Insert updated property value into entity_property_values mapping at in_class_schema_property_id. |
There was a problem hiding this comment.
Only default non required unique value hashes can be removed, otherwise we only update its respective hash.
bedeho
left a comment
There was a problem hiding this comment.
This basically looks correct now, well done!
Just one comment about a minor refactor possibility for clarity, and then what we discussed about loud failure and asserting no error in extrinsics.
|
|
||
| /// Compute old and new unique property value hashes. | ||
| /// Ensure new property value hashes with `unique` flag set are `unique` on `Class` level | ||
| pub fn ensure_property_values_hashes( |
There was a problem hiding this comment.
This ensure checkers has a name that does not really indicate a clear purpose.
Closer inspection shows that it seems to do three things
- check that new property values respect uniquness constraint
- if so, compute hashes representing these values values
- if so, determine what hashes must be removed from the uniquness index because they represent values that will no longer be in directory.
It seems that only 1 or 2 are really part of the ensure check, and you could perhaps have one checker with a name like ensure_new_property_values_respect_uniquness. It can then return hashes in success case. Then for 3, which is only relevant if you go to mutation, you do the call to compute_old_unique_hashes somewhere else. Could be a standalone call, or it could be inside remove_unique_property_value_hashes or something else.
There was a problem hiding this comment.
Agree, refactored it here 673fcb3
Thank you for the good explanation!
The scope of this PR includes:
Uniqueness feature - store only property value hashes instead of actual values #1123
Closes: #1123, #1021
To minimize merge conflict potential, this PR assumes #1035 will be merged first.